package com.heima.behavior.service.impl;

import com.heima.behavior.dto.BehaviorDto;
import com.heima.behavior.entity.ApBehaviorEntry;
import com.heima.behavior.entity.ApFollowBehavior;
import com.heima.behavior.mapper.ApFollowBehaviorMapper;
import com.heima.behavior.service.IApBehaviorEntryService;
import com.heima.behavior.service.IApFollowBehaviorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.dto.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * APP关注行为表 服务实现类
 * </p>
 *
 * @author syl
 * @since 2022-07-05
 */
@Service
public class ApFollowBehaviorServiceImpl extends ServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior> implements IApFollowBehaviorService {


    @Autowired
    private IApBehaviorEntryService apBehaviorEntryService;


    @Override
    public ResponseResult saveFollowBehavior(BehaviorDto dto) {

        ApFollowBehavior apFollowBehavior = new ApFollowBehavior();


        ApBehaviorEntry entry = apBehaviorEntryService.getBehaviorEntryByUserIdOrEquipmentId(dto.getUserId(),dto.getEquipmentId());
        apFollowBehavior.setEntryId(entry.getId());
        apFollowBehavior.setFollowId(dto.getAuthorId());
        apFollowBehavior.setOperation(dto.getOperation());
        apFollowBehavior.setCreatedTime(new Date());
        this.save(apFollowBehavior);
        return ResponseResult.okResult();
    }
}
